import axios from 'axios'
const service = axios.create({
	timeout: 5000, // request timeout
})

// 请求拦截 
service.interceptors.request.use(
	config => {
		if ((config.method).toLowerCase() === 'get') config.params = config.data;
		if (config.headers['Content-Type']) {
			config.headers['Content-Type'] = 'application/json';
		}
		return config
	},
	error => {
		Promise.reject(error)
	}
)

//响应拦截
service.interceptors.response.use(
	response => {
		return response.data;
	}, error => {
		return Promise.reject(error)
	})

export default service